import { onMounted } from 'vue'
import { ref, reactive } from 'vue'
import { getAssetsImages } from '@/utils/utils'
import { centerStore } from '@/store/center/index'
import { getHomeDataApi, editInfoApi,getCenterDataApi } from '@/api/center'
import { SettingParm } from '@/api/center/CenterModel'
import useInstance from '@/hooks/useInstance'
import { useRouter } from 'vue-router'
import { isRes } from '@/utils/pub-use'
export default function useCenter() {
	const store = centerStore()
	const router = useRouter()
	//获取全局属性
	const { global } = useInstance()
	const listData: any = reactive({
		info: {}
	})
	let centerData:any =ref({})
	const changeStatus = () => {
		store.setCollapse()
	}
	const tuanlist = reactive([
		{
			title: '团购管理',
			icon: getAssetsImages('center', 'tuan.png'),
			url: '/grouponmanage'
		},
		{
			title: '订单管理',
			icon: getAssetsImages('center', 'order.png'),
			url: '/ordermanage'
		},
		{
			title: '自提点管理',
			icon: getAssetsImages('center', 'address.png'),
			url: '/addressmanage'
		},
		{
			title: '核销扫码',
			icon: getAssetsImages('center', 'code.png'),
			url: ''
		},
		{
			title: '团长设置',
			icon: getAssetsImages('center', 'fankui.png'),
			url: '/tuansetting'
		}
	])
	const tuanYuanlist = reactive([
		{
			title: '收货地址',
			icon: getAssetsImages('center', 'address.png'),
			url: '/address'
		},
		{
			title: '反馈投诉',
			icon: getAssetsImages('center', 'edit.png'),
			url: '/feedbackinfo'
		},
		{
			title: '设置',
			icon: getAssetsImages('center', 'fankui.png'),
			url: '/setting'
		}
	])
	const handleRouter = (item: { url: string }) => {
		if (item.url) {
			router.push({
				path: item.url
			})
		} else {
			router.push({
				path: '/404'
			})
		}
	}
	const getInfo = async () => {
		let res = await getHomeDataApi()
		const { code, result } = res
		if (code == 0) {
			const { data } = result
			listData.info = data
		}
	}
	const getCenterData =async ()=>{
		let res = await getCenterDataApi()
		if(isRes(res)){
			centerData.value = res.result
		}
	}
	 const handlejump: any = () => {
			router.push({
				path: '/setting'
			})
		}
	onMounted(() => {
		getInfo()
		getCenterData()
	})
	return {
		changeStatus,
		tuanlist,
		tuanYuanlist,
		handleRouter,
		listData,
		handlejump,
		centerData
	}
}
